﻿using System;
using System.ComponentModel;

namespace N2.ComponentModel
{
	public class ContentItemTypeDescriptionProvider
		: TypeDescriptionProvider
	{
		#region Fields

		//readonly TypeDescriptionProvider parent;
		
		#endregion Fields

		#region Constructors

		public ContentItemTypeDescriptionProvider(TypeDescriptionProvider parent)
			: base(parent) {}

		public ContentItemTypeDescriptionProvider()
			: this(TypeDescriptor.GetProvider(typeof(ContentItem)))
		{
		}

		#endregion Constructors

		public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
		{
			if (null != instance && !(instance is ContentItem)) {
				throw new ArgumentException("instance");
			}
			
			return new ContentItemTypeDescriptor(
				base.GetTypeDescriptor(objectType, instance),
				instance as ContentItem);
		}
	}
}
